import { useEffect, useState } from 'react';
import Taro, { setStorageSync } from "@tarojs/taro";
// import { useNavigate, Link } from 'react-router-dom'
import '../../utils/http'
import { View, Text, Image, Input, Button, Radio, Navigator } from '@tarojs/components'
import { AtButton } from 'taro-ui'
import "taro-ui/dist/style/components/button.scss" // 按需引入
import logopng from '../../static/images/tu.png'
import './login.scss'
import http from '../../utils/http';

const Login = () => {
  const Reset = () => {
    wx.navigateTo({
      url: '../password/password'
    })
  }
  const [value, setValue] = useState('')
  const [pass, setPass] = useState('')
  const Get = () => {
    http({
      url: '/role/userLogin',
      // url: '/user/orderDetailsQuery',
      // params: values,
      data: {
        phone: value,
        password: pass,
        // phone: '',
        // password: '111111',
        // token: ''
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      method: 'post'

    }).then((res) => {
      console.log(res.data)
      console.log(res.data.data);
      // console.log(res.data.data.token);
      console.log(value)
      if (res.data.code === 200) {
        // message.success('登录成功');


        Taro.setStorageSync('token', res.data.data.token)
        Taro.setStorageSync('phone', value)
        Taro.setStorageSync('password', pass)
        Taro.reLaunch({
          url: '../wode/wode'
        })
      }
    })
    // console.log("Success:", values);
  }

  return <View>
    <View className='imag'>
      <Image src={logopng}></Image>
    </View>
    <View>
      <Input type='number' placeholder='请输入手机号码' maxlength='11' onInput={value => {
        setValue(value.detail.value)
        // console.log("phone", value.detail.value);;
      }} />
      <Input type='password' password placeholder='请输入登录密码' onInput={pass => {
        setPass(pass.detail.value)
        // console.log(pass.detail.value);
      }} />
      <Text className='password' onClick={Reset}>忘记密码</Text>
    </View>
    <AtButton className='btn' type='primary' size='normal' onClick={Get}>立即登录</AtButton>
    <Navigator url='../register/register' > <AtButton className='btn' type='secondary' size='normal' >注册账号</AtButton></Navigator>



    <View className='checked'>
      <Radio value='选中' checked></Radio>
      <Text>登录即表明同意<Text className='xieyi'>《用户协议》</Text>和<Text className='xieyi'>《隐私政策》</Text></Text>
    </View>
  </View>

}
export default Login